namespace ShellNavigator.Client.Models
{
  #region

  using System.Collections.Generic;
  using System.Linq;

  using ShellNavigator.Client.Core;

  #endregion

  /// <summary>
  ///     The solution target.
  /// </summary>
  public class SolutionInfo : InfoBase
  {
    #region Constants and Fields

    public SolutionInfo(ProjectInfo project)
    {
      this.Projects = new[] { new ProjectInfo(project, this) };
    }

    public SolutionInfo(IEnumerable<ProjectInfo> projects)
    {
      this.Projects = projects.Select(project => new ProjectInfo(project, this));
    }


    #endregion

    #region Public Properties

    public string Name { get; set; }

    public IEnumerable<ProjectInfo> Projects { get; private set; }

    #endregion

    #region Public Methods

    public override void RunAction(AppActions action)
    {
      switch (action)
      {
        case AppActions.OpenSolution:
          ShellExecutor.OpenStudio(this.Name, this.Projects.SelectMany(p => p.Files.Select(x => x.Name)));
          break;
        case AppActions.OpenProject:
          ShellExecutor.OpenStudio(this.Name);
          break;
        case AppActions.OpenFile:
          ShellExecutor.OpenShell(this.Name);
          break;
        case AppActions.CopyFile:
          ShellExecutor.CopyToClipboard(this.Projects.SelectMany(p => p.Files.Select(x => x.Name)));
          break;
        case AppActions.CopyProject:
          ShellExecutor.CopyToClipboard(this.Projects.Select(p => p.Name));
          break;
        case AppActions.CopyAssembly:
          ShellExecutor.CopyAssemblyName(this.Projects.Select(p => p.Name));
          break;
        case AppActions.CopySolution:
          ShellExecutor.CopyToClipboard(this.Name);
          break;
      }
    }

    #endregion
  }
}